<?php
/**
 * Created by PhpStorm.
 * User: jocky
 * Date: 05/09/2017
 * Time: 13:11
 */
?>

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">资金明细</h3>
                <ul class="panel-controls">
                    <li>
                        <a href="javascript:void(0)" class="panel-fullscreen"
                           onclick="panel_fullscreen($(this).parents(' .panel'));">
                            <span class="fa fa-expand"></span>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)" class="panel-refresh"
                           onclick="moneyObj.history(3,0)">
                            <span class="fa fa-refresh"></span>
                        </a>
                    </li>
                </ul>
            </div>
            <div class="panel-body">
                <form class="form-inline" role="form" id="money_history_form">
                    <div class="form-group">
                        <label class="sr-only">变更类型</label>
                        <select class="form-control" name="direction">
                            <option value="-1">变更类型 - 全部</option>
                            <?php
                            $option = '';
                            foreach ($directions as $v) {
                                $option .= "<option value='" . $v['id'] . "'>" . $v['name'] . "</option>";
                            }
                            echo $option;
                            ?>
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">开始时间</label>
                        <input name='from'
                               type="text"
                               class="form-control datepicker"
                               placeholder="开始时间"
                               value="<?= date('Y-m-d', $from) ?>">
                    </div>
                    <div class="form-group">
                        <label class="sr-only">结束时间</label>
                        <input name="to"
                               type="text"
                               class="form-control datepicker"
                               placeholder="结束时间"
                               value="<?= date('Y-m-d', $to) ?>">
                    </div>
                    <div class="form-group">
                        <button type="button" class="btn btn-block btn-default" onclick="moneyObj.history(1,1)">
                            查 询
                        </button>
                    </div>

                </form>
                <br/>
                <div class="table-responsive">
                    <table class="table table-striped table-bordered" id="money_history_table">
                        <thead>
                        <tr>
                            <th>类型</th>
                            <th class="text-center">时间</th>
                            <th class="text-right">金额</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                        $color = '';
                        $sumMoney = number_format($sumMoney, 2, '.', '');
                        if ($sumMoney > 0) {
                            $color = 'red';
                        }
                        if ($sumMoney < 0) {
                            $color = 'green';
                        }
                        ?>
                        <tr>
                            <td><i style="color: red;">汇总</i></td>
                            <td></td>
                            <td class="text-right" style="color: <?= $color ?>"><?= $sumMoney; ?></td>
                        </tr>
                        <?php
                        $tr = '';
                        foreach ($lists as $v) {
                            $color = '';
                            if ($v['money'] > 0) {
                                $color = 'red';
                            } else {
                                if ($v['money'] < 0) {
                                    $color = 'green';
                                }
                            }
                            $money = (float)$v['money'];

                            $tr .= "<tr>";
                            $tr .= "<td>" . $v['direction'] . "</td>";
                            $tr .= "<td class='text-center'>" . date('Y-m-d H:i:s', $v['time']) . "</td>";
                            $tr .= "<td class='text-right' style='color: " . $color . ";'>" . $money . "</td>";
                        }
                        echo $tr;
                        ?>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class=" panel-footer
                            ">
                <form class="form-inline text-center">
                    <div class="form-group">
                        <button class="btn-block btn btn-default" type="button"
                                onclick="moneyObj.history(1,1)">
                            &lt;&lt;
                        </button>
                    </div>
                    <div class="form-group">
                        <button class="btn-block btn btn-default" type="button"
                                onclick="moneyObj.history(2,1)">
                            &lt;
                        </button>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">
                                共 <span id="money_history_pageTotal"><?= $pageTotal; ?></span> 页
                            </span>
                            <input type="number"
                                   min="1"
                                   class="form-control"
                                   id="money_history_pageNo"
                                   placeholder="请输入要跳转的页码"
                                   value="1"
                                   style="text-align: center;">
                            <span class="input-group-btn">
                                <button type="button"
                                        class="btn btn-default"
                                        onclick="moneyObj.history(3,0)">
                                    翻 页
                                </button>
                            </span>

                        </div>
                    </div>

                    <div class="form-group">
                        <button class="btn-block btn btn-default" type="button"
                                onclick="moneyObj.history(2,2)">
                            &gt;
                        </button>
                    </div>
                    <div class="form-group">
                        <button class="btn-block btn btn-default" type="button"
                                onclick="moneyObj.history(1,2)">
                            &gt;&gt;
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    $('#money_history_form').find('.datepicker').datepicker({
        autoclose: true,
        format: "yyyy-mm-dd"
    });
</script>